<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>银行卡列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-table-body .layui-table-cell {
            height: 50px; line-height: 50px;
        }
        .layui-laypage .layui-laypage-curr .layui-laypage-em{ background-color: #1E9FFF; }
        .layui-form-checked[lay-skin=primary] i{border-color: #1E9FFF!important;background-color: #1E9FFF;color:#fff;}
        .layui-form-checkbox[lay-skin=primary]:hover i{border-color:#1E9FFF;color:#fff}
    </style>
</head>
<body>

<div class="layui-fluid">

    <div class="layui-col-md12">
        <div class="layui-card">

            <div lay-filter="listSearch" class="layui-form layui-card-header layuiadmin-card-header-auto" style="height:auto;padding:10px 15px;">

                <div class="layui-form-item">

                    <div class="layui-inline">
                        <input type="text" name="payee_name" placeholder="请输入收款人姓名" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="bank_account" placeholder="请输入收款银行卡号" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <input type="text" name="contact_person" placeholder="请输入收款联系人" autocomplete="off" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn  layuiadmin-btn-admin" lay-submit lay-filter="LAY-list-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="LAY-reset">重置</button>
                    </div>

                </div>

            </div>

            <div class="layui-card-body">

                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
                </div>

                <table id="LAY-list-manage" lay-filter="LAY-list-manage"></table>

            </div>

        </div>
    </div>

</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>

    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','admin'], function(){

        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        $(document).on("click", ".tab_add", function (){
            top.objOkTab.tabAdd($(this));
        });

        //监听搜索
        form.on('submit(LAY-list-front-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('LAY-list-manage', {
                where: field
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        form.on('submit(LAY-reset)', function(data){
            form.val("listSearch", {
                "payee_name": "",
                "bank_account": "",
                "contact_person": "",
            });
            form.render();
            table.reload('LAY-list-manage', {
                where: {"payee_name": "","bank_account": "","contact_person": ""}
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        //书籍管理
        table.render({
            elem: '#LAY-list-manage'
            ,url: "{:url('Bank/list_data')}" //模拟接口
            ,autoSort: false
            ,cols: [[
                {field: 'id', width: 100, title: 'ID', sort: true, align:'center'}
                ,{field: 'bank_name', title: '收款银行名称', align:'center'}
                ,{field: 'branch_title', title: '支行名称', align:'center'}
                ,{field: 'payee_name', title: '收款人姓名', align:'center'}
                ,{field: 'bank_account', title: '收款银行卡号', align:'center'}
                ,{field: 'contact_person', title: '收款联系人', align:'center'}
                ,{field: 'tel', title: '联系电话', align:'center'}
                ,{field: 'state', title: '状态', align:'center'}
            ]]
            ,page: true
            ,limit: 30
            ,height: 'full-220'
            ,text: '对不起，加载出现异常！'
        });

        //触发排序事件
        table.on('sort(LAY-list-manage)', function(obj){

            table.reload('LAY-list-manage', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });

        });

        var active = {
            add: function(){
                layer.open({
                    type: 2
                    ,title: '添加银行卡'
                    ,content: "{:url('Bank/add')}"
                    ,maxmin: true
                    ,area: ['580px', '460px']
                    ,btn: ['确定', '取消']
                    ,btnAlign: 'c'
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-data-add-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){

                            $.ajax({
                                url:"{:url('Bank/add')}",
                                type:"post",
                                dataType: "json",
                                data:data.field,
                                async:true,
                                success: function(rs){
                                    if(rs['code'] == 100){

                                        layer.msg(rs['msg'],function () {
                                            layer.close(index); //关闭弹层
                                            table.reload('LAY-list-manage');
                                        });

                                    }else{
                                        layer.msg(rs['msg']);
                                    }
                                    return false;
                                }
                            });
                        });

                        submit.trigger('click');
                    }
                });
            }
        };

        $('.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>
</html>